package com.jvyou.app.ds.controller;



import cn.dev33.satoken.annotation.SaIgnore;
import com.jvyou.app.common.domain.model.PageResult;
import com.jvyou.app.ds.domain.dto.CourseSubjectDto;
import com.jvyou.app.ds.domain.dto.LicenseTypeDto;
import com.jvyou.app.ds.domain.entity.CourseSubject;
import com.jvyou.app.ds.domain.entity.LicenseType;
import com.jvyou.app.ds.service.CourseSubjectService;
import org.springframework.web.bind.annotation.*;
import lombok.RequiredArgsConstructor;
import cn.dev33.satoken.annotation.SaCheckPermission;
import com.jvyou.app.common.domain.model.Result;
import com.jvyou.app.common.enums.HttpCodeEnum;

import java.util.List;

/**
 * 考试科目表(CourseSubject)表控制层
 *
 * @author 橘柚
 * @since 2025-04-18 14:48:56
 */
@RestController
@RequiredArgsConstructor
    @RequestMapping("/courseSubject")
public class CourseSubjectController  {
    
    private final CourseSubjectService courseSubjectService;

    @GetMapping("/list")
    @SaIgnore
    public Result<List<CourseSubject>> list(@ModelAttribute CourseSubjectDto courseSubjectDto) {
        return Result.success(courseSubjectService.listCourseSubject(courseSubjectDto));
    }

    @GetMapping("/page")
    @SaIgnore
    public Result<PageResult<CourseSubject>> page(@ModelAttribute CourseSubjectDto courseSubjectDto) {
        return Result.success(courseSubjectService.pageCourseSubject(courseSubjectDto));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/{id}")
    @SaCheckPermission("ds:courseSubject:get")
    public Result<CourseSubject> selectOne(@PathVariable Long id) {
        return Result.success(courseSubjectService.getById(id));
    }

    /**
     * 新增数据
     *
     * @param courseSubject 实体对象
     * @return 新增结果
     */
    @PostMapping
    @SaCheckPermission("ds:courseSubject:insert")
    public Result<CourseSubject> insert(@RequestBody CourseSubject courseSubject) {
        boolean success = courseSubjectService.save(courseSubject);
        return success ? Result.success(courseSubject) : Result.error(HttpCodeEnum.ADD_FAIL);
    }
    
     /**
     * 修改数据
     *
     * @param courseSubject 实体对象
     * @return 修改结果
     */
    @PutMapping("/updateById")
    @SaCheckPermission("ds:courseSubject:update")
    public Result<Boolean> updateById(@RequestBody CourseSubject courseSubject) {
        boolean success = courseSubjectService.updateById(courseSubject);
        return success ? Result.success(true) : Result.error(HttpCodeEnum.UPDATE_FAIL);
    }
    

    /**
     * 删除数据
     *
     * @param id 主键结合
     * @return 删除结果
     */
    @DeleteMapping("/{id}")
    @SaCheckPermission("ds:courseSubject:delete")
    public Result<Boolean> delete(@PathVariable Long id) {
        boolean success = courseSubjectService.removeById(id);
        return success ? Result.success(true) : Result.error(HttpCodeEnum.DELETE_FAIL);
    }
    
}

